package io.xxx.omni.mdc.site.service

import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import io.xxx.omni.mdc.model.Authorization
import io.xxx.omni.mdc.model.AuthorizationMapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class AuthorizationService {

    @Autowired
    private lateinit var authorizationMapper: AuthorizationMapper

    fun getAll(pid: String?, enabled: Boolean?): List<Authorization> {
        val wrapper = KtQueryWrapper(Authorization::class.java)
        if (pid != null)
            wrapper.eq(Authorization::pid, enabled)
        if (enabled != null)
            wrapper.eq(Authorization::enabled, enabled)
        return authorizationMapper.selectList(wrapper)
    }

    fun getOne(id: String): Authorization {
        return authorizationMapper.selectById(id)
    }
}